/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package VIMS;

import java.sql.*;

/**
 *
 * @author shyan
 */
public class Database {
    
    Connection con=null;
    Statement stmt=null;
    //Connect DB
    void connectDB()
    {
        try
        {
            //load mysql driver
            Class.forName("com.mysql.jdbc.Driver");
            con = DriverManager.getConnection("jdbc:mysql://localhost:3306/vims", "root", "123");
            
        }
        catch(SQLException e)
        {
            System.out.println("SQL Exception: "+e.toString());
        }        
        catch (ClassNotFoundException cE)
        {
            System.out.println("Class Not Found Exception: "+ cE.toString());
        }
    }
     
    //Execute & Get Query
    ResultSet getResultSet(String SQL)
    {
        connectDB();
        ResultSet outcome = null;
        try
        {
            stmt = con.createStatement();
            outcome = stmt.executeQuery(SQL);
        }
        catch (Exception Ce)
        {
            System.out.println("Class Not Found Exception: "+Ce);
        }
        
        return outcome;
    }
    
    // Update info into Database
     boolean update(String SQL)
    {
        connectDB();
        try
        {
            stmt = con.createStatement();
            stmt.executeUpdate(SQL);
            return true;
        }
        catch (SQLException ex)
        {
            System.out.println("Class Not Found Exception: "+ex);
            return false;
        }
        //return (false);
    }
}

    
   